#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 's125_nanoorchis'
__mtime__ = '2017/3/5'
"""
#保存respnse的内容为html文件
cookieStr="sd_userid=46611477323355677; sd_cookie_crttime=1477323355677; tvfe_boss_uuid=4088ef056bb05328; pac_uid=1_569128050; eas_sid=N1e4j894T6l8q7a6q4x0H2j4N5; RK=fF26s1O6dd; pgv_pvi=751090688; pgv_si=s3762871296; ptui_loginuin=569128050; uniqueuid=c0ff22fd9a923c3b48f899b8d5f7daf4; pgv_info=ssid=s3206305046&pgvReferrer=; pgv_pvid=6689437934; o_cookie=569128050; pt2gguin=o0569128050; uin=o0569128050; skey=MAOlmO4FpC; ptisp=ctc; ptcz=e21326411328d62054792d62165ca96ae63c5188c3b5131f3d8a8451a6ae0d70; MANYOU_SESSIONID_bf895=5173a011aaba08f219450ef1fb2e9e5f;qqUser=%7B%22uin%22%3A569128050%2C%22nickName%22%3A%22%5Cu65ad%5Cu6865%5Cu6b8b%5Cu96ea%22%7D; security_cookiereport=1488638674"
import requests
import re

def convertCookieStrToDict(cookieStr):
    cookies={}
    for key_value_pairs in cookieStr.split("; "):
        key_value_pair=key_value_pairs.split("=")
        cookies[key_value_pair[0]]=key_value_pair[1]
    return cookies

cookies=convertCookieStrToDict(cookieStr)
url="http://qgc.qq.com/314962432/t/125"

def saveUrl(url):
    memberNo="m"+(re.match(r'http://qgc.qq.com/314962432/t/(\d*)',url)).group(1)
    #print (memberNo)
    response = requests.get(url, cookies=cookies)
    # print(response.content.decode(encoding="utf-8"))
    f=open("../Download/"+memberNo+".html",'w')
    f.write(response.content.decode(encoding="utf-8"))
    f.close()

saveUrl(url)